<extend name="Layout::member"/>
<block name="content">
    <div class="layout-content">

        <div class="page-title">会员管理</div>

        <div class="content-top">
            <ul class="top-nav">
                <li class="active"><span>修改信息</span></li>
            </ul>
            <div class="clearfix"></div>
        </div>
        <div class="clearfix"></div>
        <!--content-main start-->
        <div class="container-fluid content-main">
            <div class="row">
                <div class="col-md-12">
                    <div id="tsk" class="ui-tips bg-info" style="display:none">
                        <span class="icon glyphicon glyphicon-info-sign"></span> <span
                            id="ts">提示信息提示信息提示信息提示信息提示信息提示信息。</span>
                    </div>

                    <form class="form-horizontal" onsubmit="return false">
                        <input type="hidden" value="{$list['id']}" class="js-id"/>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">城市</label>
                            <div class="col-sm-5">
                                <input type="text" value="{$list['city']}" class="form-control js-city"/>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">区域</label>
                            <div class="col-sm-5">
                                <select class="form-control js-area" name="area">
                                    <foreach name="areas" item="area">
                                        <option data-area="{$area.id}" value="{$area.id}">{$area.name}</option>
                                    </foreach>
                                </select>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">小区</label>
                            <div class="col-sm-5">
                                <input type="text" class="form-control js-plot" value="{$list['plot']}"/>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">面积</label>
                            <div class="col-sm-5">
                                <input type="text" class="form-control js-place" value="{$list['place']}"/>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">风格</label>
                            <div class="col-sm-5">
                                <select class="form-control js-style" name="style">
                                    <foreach name="styles" item="style">
                                        <option data-style="{$style.id}" value="{$style.id}">{$style.name}</option>
                                    </foreach>
                                </select>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">预算</label>
                            <div class="col-sm-5">
                                <input type="text" class="form-control js-butget" value="{$list['butget']}"/>
                                <span class="help-block"></span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">备注</label>
                            <div class="col-sm-5">
                                <textarea class="form-control js-remark" value="{$list['remark']}"></textarea>
                                <span class="help-block"></span>
                            </div>
                        </div>


                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-8">
                                <button onclick="func()" style="margin-left: 90px;width: 150px" type="submit"
                                        class="btn btn-default">保存
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!--content-main end-->
    </div>
    <script>
        $(function () {
            $('option[data-area={$list["area_id"]}]').attr("selected", true);
            $('option[data-style={$list["style_id"]}]').attr("selected", true);
        })
        function func() {
            var city = $('.js-city').val();
            if (city == '') {
                $('#tsk').css('display', 'block');
                $('#ts').html("城市不能为空");
                return false;
            }

            var plot = $('.js-plot').val();
            if (plot == '') {
                $('#tsk').css('display', 'block');
                $('#ts').html("小区不能为空");
                return false;
            }
            //var place=$('.js-style').val()
            var butget = $('.js-butget').val();
            if (butget == '') {
                $('#tsk').css('display', 'block');
                $('#ts').html("报价不能为空");
                return false;
            }
            var place = $('.js-place').val();
            if (place == '') {
                $('#tsk').css('display', 'block');
                $('#ts').html("面积不能为空");
                return false;
            }
            var id = $('.js-id').val();
            var area = $('.js-area').val();
            var style_id=$('.js-style').val();
            var remark=$('.js-remark').val();


            //alert(area);return false;
            // alert(sex);
            // return false;
            $.ajax({
                type: 'POST',
                url: "{:U('Match/doUpdate')}",
                data: {
                    'city': city,
                    'area_id':area,
                    'plot': plot,
                    'style_id':style_id,
                    'place':place,
                    'butget':butget,
                    'remark':remark,
                    'id': id
                },
                dataType: 'json',
                success: function (data) {
                    //alert(data);
                    /* console.dir(JSON.parse(data));
                     return false;*/
                    if (data == 1) {
                        $('#tsk').css('display', 'block');
                        $('#ts').html('修改成功');
                        setTimeout(function () {
                            location.href = "{:U('Match/index')}";
                        }, 1000);
                    } else if (data == 2) {
                        $('#tsk').css('display', 'block');
                        $('#ts').html('修改失败');
                    }
                }
            })
        }
    </script>
</block>
